﻿package main

import (
    "fmt"
    //"time"
    "sync"
)

var lock sync.RWMutex
func main() {
    pipe := make(chan int, 10000)
    var count int = 0
    for i := 0; i < 1000; i++ {
        go func(n *int, p chan int){
            lock.Lock()
            *n++
            //time.Sleep(time.Millisecond)  // 加点延迟，效果会很明显
            p <- *n
            lock.Unlock()
        }(&count, pipe)
    }
    for i := 0; i < 1000; i++ {
        res := <- pipe
        fmt.Println(res)
    }
}